package com.dayuanit.dy14.atm.demo2.dy14atmcommon.util;

public class PageUtils {
    //每页显示的个数
    public static final int pre_page_number = 2;

    //总页数
    private int totalPageNumber;

    //总条数
    private int totalDataNumbers;

    //当前页
    private int currentPage;

    //偏移量
    private int offset;

    //每页展示的数据
    private Object data;

    private PageUtils(int currentPage, int totalDataNumbers) {
        this.currentPage = currentPage;
        this.totalDataNumbers = totalDataNumbers;
    }

    public static PageUtils build(int currentPage, int totalDataNumbers) {
        return new PageUtils(currentPage, totalDataNumbers);
    }

    public PageUtils init() {
        this.offset = (currentPage - 1) * pre_page_number;
        this.totalPageNumber = (totalDataNumbers % pre_page_number) == 0 ? totalDataNumbers / pre_page_number : totalDataNumbers / pre_page_number + 1;
        return this;
    }

    public int offset() {
        return offset;
    }

    public Object getData() {
        return data;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public int getTotalPageNumber() {
        return totalPageNumber;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
